package org.FaPe3D.core.parsers.casting
{
	import com.adobe.serialization.json.JSON;
	
	public class Common
	{
		public function Common()
		{
		}
		
		public static function cast(type:String, value:*):*
		{
			var result:*;
			
			switch ( type )
			{
				case 'String' :
				
					result = value.toString();
				
				break;
				
				case 'int' :
				
					result = int( Number( value ) );
				
				break;
				
				case 'uint' :
				
					result = uint( Number( value ) );
				
				break;
				
				case 'Number' :
				
					result = Number( value );
				
				break;
				
				case 'Boolean' :
					
					if(Number( value ).toString() !=  'NaN')
					{
						value = Boolean( Number( value ) );
					}else
					{
						value = value.toLowerCase();
						value = (value == 'true' ? true : false);
					}
					
					result = Boolean( value );
				break;
				
				case 'null' :
					result = null;
				break;
				
				case 'undefined' :
					result = undefined;
				break;
				
				case 'Object':
					result = JSON.decode( value );
				break;
				
				case 'Array':
					result = JSON.decode( value );
				break;
					
				default :
				
					result = value.toString();
				
				break;
			}
			
			return result;
		}
		
	}
}